package org.net.cms.mapper;

import org.apache.ibatis.annotations.*;
import org.net.cms.dao.ParentAccountDto;

import java.util.List;

@Mapper
public interface ParentAccountMapper {

    @Select("select * from parent_account where phone = #{phone} and deleted = 0")
    ParentAccountDto getParentAccountByPhone(String phone);

    @Select("select * from parent_account where id = #{id} and deleted = 0")
    ParentAccountDto getParentAccountById(int id);

    @Select("SELECT * FROM parent_account WHERE deleted = 0 AND phone != '10000000000'")
    List<ParentAccountDto> getParentAccountList();

    @Select("select id from parent_account where phone = #{phone} and password = #{password}")
    int login(String phone, String password);

    @Update("update parent_account set studentList = #{studentList} where id = #{id} and deleted = 0")
    int updateParentAccount(String studentList, int id);

    @Update("update parent_account set deleted = 1 where id = #{id} and deleted = 0")
    int deleteParentAccount(int id);

    @Update("update parent_account set password = #{password} where id = #{id} and deleted = 0")
    int resumePassword(int id, String password);

    @Insert("INSERT INTO parent_account (parent_card_id, phone, password, studentList) " +
            "VALUES (#{parentCardId}, #{phone}, #{password}, #{studentList})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int addParentAccount(ParentAccountDto parentAccount);

    // 根据家长id查询学生列表
    @Select("select studentList from parent_account where id = #{id} and deleted = 0")
    String getMyStudentById(int id);

    @Select("select id from parent_account where parent_card_id = #{cardId}")
    int getParentIdByCardId(String cardId);

    // 根据电话号码查找密码
    @Select("select password from parent_account where phone = #{phone} and deleted = 0")
    String getOldPasswordByPhone(String phone);
}
